import Quill from 'quill';
import Dragon from '../../shared/dragon';

const BlockEmbed = Quill.import('blots/block/embed');

class DragonBlot extends BlockEmbed {
  static blotName = 'dragon';
  static tagName = 'canvas';

  static create(value): any {
    const node = super.create(value);
    const { id, width, height } = value;

    node.setAttribute('id', id || DragonBlot.blotName);
    if (width !== undefined) {
      node.setAttribute('width', width);
    }
    if (height !== undefined) {
      node.setAttribute('height', height);
    }

    const dragon = new Dragon(node);
    return node;
  }
}

export default DragonBlot;
